package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.BusNewsNotice;
import com.ruoyi.app.service.IBusNewsNoticeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @author pc
 * @version 1.0
 * @description: TODO
 */
@RestController
@RequestMapping("/app/busNewsNotice")
public class BusNewsNoticeController extends BaseController {


    @Resource
    private IBusNewsNoticeService busNewsNoticeService;


    /**
     * 查询业务数据--通知公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusNewsNotice busNewsNotice)
    {
        startPage();
        List<BusNewsNotice> list = busNewsNoticeService.selectBusNewsNoticeList(busNewsNotice);
        return getDataTable(list);
    }

    /**
     * 导出业务数据--通知公告列表
     */
    @Log(title = "业务数据--通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusNewsNotice busNewsNotice)
    {
        List<BusNewsNotice> list = busNewsNoticeService.selectBusNewsNoticeList(busNewsNotice);
        ExcelUtil<BusNewsNotice> util = new ExcelUtil<BusNewsNotice>(BusNewsNotice.class);
        util.exportExcel(response, list, "通知公告");
    }

    /**
     * 获取业务数据--通知公告详细信息
     */
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId)
    {
        return success(busNewsNoticeService.selectBusNewsNoticeByNoticeId(noticeId));
    }

    /**
     * 新增业务数据--通知公告
     */
    @Log(title = "业务数据--通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/saveBusNewsNotice")
    public AjaxResult add(@RequestBody BusNewsNotice BusNewsNotice)
    {
        return toAjax(busNewsNoticeService.insertBusNewsNotice(BusNewsNotice));
    }

    /**
     * 修改业务数据--通知公告
     */
    @Log(title = "业务数据--通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBusNewsNotice")
    public AjaxResult edit(@RequestBody BusNewsNotice BusNewsNotice)
    {
        return toAjax(busNewsNoticeService.updateBusNewsNotice(BusNewsNotice));
    }

    /**
     * 删除业务数据--通知公告
     */
    @Log(title = "业务数据--通知公告", businessType = BusinessType.DELETE)
    @PostMapping("/deleteById")
    public AjaxResult deleteById(Long noticeId)
    {
        return toAjax(busNewsNoticeService.deleteBusNewsNoticeByNoticeId(noticeId));
    }

    /**
     * @title changeNoticeState
     * @Description   通知发布、取消发布操作
     * @param busNewsNotice 业务数据--通知公告
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @Log(title = "业务数据--通知公告--修改通知发布状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeNoticeState")
    public AjaxResult changeNoticeState(@RequestBody BusNewsNotice busNewsNotice){
        busNewsNotice.setReleaseTime(new Date());
        return toAjax(busNewsNoticeService.updateBusNewsNotice(busNewsNotice));
    }
}
